#!/usr/bin/env python3
"""
LSTM训练项目演示脚本
"""

import os
import sys

# 添加当前目录到Python路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

def main():
    print("=== LSTM训练项目演示 ===\n")
    
    # 检查依赖
    print("1. 检查项目依赖...")
    try:
        import torch
        import torchvision
        import numpy
        import pandas
        import matplotlib
        import sklearn
        import seaborn
        print("✓ 所有依赖包已安装")
    except ImportError as e:
        print(f"✗ 缺少依赖包: {e}")
        print("请运行: pip install -r requirements.txt")
        return
    
    # 检查数据文件
    print("\n2. 检查数据文件...")
    from config import DATA_CONFIG
    if os.path.exists(DATA_CONFIG['data_path']):
        print("✓ 数据文件存在")
        import pandas as pd
        df = pd.read_csv(DATA_CONFIG['data_path'])
        print(f"  数据大小: {df.shape}")
        print(f"  特征列: {DATA_CONFIG['feature_columns']}")
        print(f"  目标列: {DATA_CONFIG['target_column']}")
    else:
        print("✗ 数据文件不存在")
        print(f"  请确保 {DATA_CONFIG['data_path']} 存在")
        return
    
    # 检查模型配置
    print("\n3. 检查模型配置...")
    from config import MODEL_CONFIG, TRAIN_CONFIG
    print(f"  输入维度: {MODEL_CONFIG['input_size']}")
    print(f"  隐藏层维度: {MODEL_CONFIG['hidden_size']}")
    print(f"  LSTM层数: {MODEL_CONFIG['num_layers']}")
    print(f"  输出维度: {MODEL_CONFIG['output_size']}")
    print(f"  序列长度: {TRAIN_CONFIG['sequence_length']}")
    print(f"  批次大小: {TRAIN_CONFIG['batch_size']}")
    print(f"  训练轮数: {TRAIN_CONFIG['num_epochs']}")
    print(f"  学习率: {TRAIN_CONFIG['learning_rate']}")
    print(f"  训练设备: {TRAIN_CONFIG['device']}")
    
    # 检查模型定义
    print("\n4. 检查模型定义...")
    try:
        from models.lstm_model import create_model
        model = create_model('basic', **MODEL_CONFIG)
        print("✓ 模型定义正常")
        print(f"  模型参数数量: {sum(p.numel() for p in model.parameters())}")
    except Exception as e:
        print(f"✗ 模型定义错误: {e}")
        return
    
    # 检查工具函数
    print("\n5. 检查工具函数...")
    try:
        from utils import create_sequences, load_and_preprocess_data
        
        # 测试序列创建
        test_data = [[1.0], [2.0], [3.0], [4.0], [5.0]]
        sequences, targets = create_sequences(test_data, 3)
        print("✓ 序列创建功能正常")
        print(f"  创建的序列形状: {sequences.shape}")
        
        # 测试数据加载
        X_train, X_test, y_train, y_test, scaler = load_and_preprocess_data(
            DATA_CONFIG['data_path'],
            DATA_CONFIG['feature_columns'],
            DATA_CONFIG['target_column'],
            TRAIN_CONFIG['sequence_length'],
            TRAIN_CONFIG['train_split']
        )
        print("✓ 数据加载功能正常")
        print(f"  训练集形状: {X_train.shape}")
        print(f"  测试集形状: {X_test.shape}")
        
    except Exception as e:
        print(f"✗ 工具函数错误: {e}")
        return
    
    print("\n=== 演示完成 ===")
    print("\n下一步操作:")
    print("1. 运行训练: python train.py")
    print("2. 运行预测: python predict.py")
    print("3. 查看训练结果: 查看生成的图片文件")
    print("\n项目结构:")
    print("├── config.py          # 配置文件")
    print("├── train.py           # 训练脚本")
    print("├── predict.py         # 预测脚本")
    print("├── demo.py            # 演示脚本")
    print("├── models/lstm_model.py # 模型定义")
    print("├── utils.py           # 工具函数")
    print("├── data/sample_data.csv # 示例数据")
    print("└── requirements.txt   # 依赖列表")

if __name__ == "__main__":
    main()